package com.feidee.data.report.util;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class ResultResponseUtil {

	private static Logger logger = Logger.getLogger(ResultResponseUtil.class);

	/**
	 * 如果是自定义报表,返回异常信息给前端
	 * @param returnUrl
	 * @param applyId
	 * @param status
	 * @param errMsg
	 */
	public static void resultResponse(String returnUrl, String applyId, String status, String errMsg ) {
		Map<String, String> returnMap = new HashMap<String, String>();
		returnMap.put("taskStatus", status);
		returnMap.put("applyId", applyId);
		returnMap.put("errMsg", errMsg);
		logger.info("自定义报表 " + applyId + " Custom Report returnMap:" + returnMap.toString());
		try {
			HttpConnectionManager.sendPOST(returnUrl, returnMap);
		} catch (Exception e) {
			logger.info("自定义报表, 返回结果失败...");
		}
	}

	/**
	 * 如果是自定义报表,休眠5秒后返回异常信息给前端
	 * @param returnUrl
	 * @param applyId
	 * @param status
	 * @param errMsg
	 */
	public static void sleepThenResultResponse(final String returnUrl, final String applyId, final String status, final String errMsg ) {
		new Thread() {
			@Override
			public void run() {
				try {
					Thread.sleep(5000);
					resultResponse(returnUrl, applyId, status, errMsg);
				} catch (Exception e) {
					logger.info("自定义报表数据源校验失败, 返回结果失败...", e);
				}
			}
		}.start();
	}

}
